/*
 * jQuery SlowFade v1.0
 * http://modification-blog.blogspot.com
 *
 * Copyright 2011, Hendriono
 * Free to use and abuse under the MIT license.
 * http://www.opensource.org/licenses/mit-license.php
 * 
 * March 2011
 */
(function ($) {
    $.fn.slowfade = function (default_options) {
        var defaults = {
            duration: 400,
            opacity: 1,
            add_inner_html: false,
            use_class: false,
            use_span_class: false,
            ie6comp: false
        };
        var default_options = $.extend(defaults, default_options);
        return this.each(function () {
            var my = $(this);
            var $pos = my.css("position") == "absolute" ? "absolute" : "relative";
            var $bg = my.css("background-position") === undefined ? my.css("background-position-x") + ' ' + my.css("background-position-y") : my.css("background-position");
            var $inner_html = default_options.add_inner_html ? my.text() : "";
            if (!default_options.use_class) {
                my.css({
                    position: $pos,
                    backgroundPosition: "right bottom"
                });
            } else {
                my.addClass(default_options.use_class);
            }
            if (!default_options.use_span_class) {
                $hover_replace = $('<span>' + $inner_html + '</span>').appendTo(my).css({
                    height: my.height(),
                    width: my.width(),
                    backgroundImage: my.css("background-image"),
                    backgroundPosition: $bg,
                    cursor: "pointer",
                    position: "absolute",
                    top: "0",
                    left: "0",
                    display: "block"
                });
            } else {
                $hover_replace = $('<span class="' + default_options.use_span_class + '">' + $inner_html + '</span>').appendTo(my);
            }
            if (default_options.ie6comp && $.browser.msie && $.browser.version.substr(0, 1) < 7) {
                $hover_replace.css({
                    height: my.height(),
                    width: my.width()
                }).addClass(default_options.ie6comp);
            }
            $hover_replace.hover(

            function () {
                $(this).stop().animate({
                    opacity: 0
                }, default_options.duration);
                if (default_options.opacity != 1) my.stop().animate({
                    opacity: default_options.opacity
                }, default_options.duration);
            }, function () {
                $(this).stop().animate({
                    opacity: 1
                }, default_options.duration);
                if (default_options.opacity != 1) my.stop().animate({
                    opacity: 1
                }, default_options.duration);

            });
        });
    }
})(jQuery);